package com.coder520.servicestudy;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;
import android.support.annotation.Nullable;
import android.util.Log;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by huang on 2017/7/8.
 */

public class StudentService2 extends Service {
    private static final String TAG = StudentService2.class.getSimpleName();
    private List<Student> mStudents = new ArrayList<>();
    private StudentServiceImpl mServiceImpl;

    @Override
    public void onCreate() {
        super.onCreate();
        mServiceImpl = new StudentServiceImpl();
    }

    private class StudentServiceImpl extends IStudentManager.Stub {
        @Override
        public void printString(String content) throws RemoteException {
            Log.d(TAG, "code520 printString called content is:" + content);
        }
        @Override
        public int getStudentCount() throws RemoteException {
            return mStudents.size();
        }

        @Override
        public void addStudent(Student student) throws RemoteException {
            Log.d(TAG, "code520 addStudent called student is:" + student);
            mStudents.add(student);
        }

    }
    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return mServiceImpl;
    }
}
